var mapIds = [993173250];
var 准备地图 = 993173350;

function init() {}

function setup(c, a) {
    em.setProperty("state", 1);
    em.setProperty("leader", "true");
    var c = em.newInstance("荣耀活动_塞尔提乌城墙_闪电防御作战");
    for (var b = 0; b < mapIds.length; b++) {
        var d = c.setInstanceMap(mapIds[b]);
        d.resetFully()
    }
    c.schedule("刷怪", 43 * 1000);
    c.schedule("攻击", 3 * 1000);
    c.schedule("闪电风暴", 60 * 1000);
    c.setProperty("energy", 0);
    return c
}

function 刷怪(a) {
    var b = a.getMapInstance(0);
    if (b.countMonsterById(9833638) < 2) {
        b.spawnMonsterOnGroundBelow(em.getMonster(9833638), new java.awt.Point(1092, -311));
        b.spawnMonsterOnGroundBelow(em.getMonster(9833638), new java.awt.Point(874, -311))
    }
    a.getPlayers().forEach(function (c) {
        c.getAPI().getWeatherEffectNotice("火焰精灵现身，正攻击保护膜！", 298, 5000, 1);
        c.getAPI().playerMessage(5, "火焰精灵现身，正攻击保护膜！")
    });
    a.schedule("刷怪", 43 * 1000)
}

function 攻击(a) {
    var c = a.getMapInstance(0);
    if (c.countMonsterById(9833638) > 0) {
        var b = Math.max(0, a.getNumberProperty("energy") - c.countMonsterById(9833638) * 3);
        a.setProperty("energy", b);
        a.getPlayers().forEach(function (d) {
            d.getAPI().cerniumLightningDefenseReactorEnergy(b)
        })
    }
    a.schedule("攻击", 3 * 1000)
}

function 闪电风暴(a) {
    a.getPlayers().forEach(function (b) {
        b.getAPI().cerniumLightningDefenseAttack()
    });
    if (a.getNumberProperty("energy") >= 400) {
        a.setProperty("energy", a.getNumberProperty("energy") - 400);
        a.getPlayers().forEach(function (b) {
            b.getAPI().getWeatherEffectNotice("保护膜已被激活，成功抵挡了敌人的攻击。", 298, 5000, 1);
            b.getAPI().playerMessage(5, "保护膜已被激活，成功抵挡了敌人的攻击。");
            b.getAPI().addNumberForQuestInfo(100339, "m2", 1)
        })
    } else {
        a.setProperty("energy", 0);
        a.getPlayers().forEach(function (b) {
            b.getAPI().getWeatherEffectNotice("未能成功抵挡敌人的攻击。", 298, 5000, 1);
            b.getAPI().playerMessage(5, "未能成功抵挡敌人的攻击。")
        })
    }
    a.schedule("闪电风暴", 60 * 1000)
}

function onPlayerRegistered(b, a) {
    a.setReviveCount(-100);
    var c = b.getMapInstance(0);
    a.changeMap(c, c.getPortal(0))
}

function onPlayerRevived(b, a) {
    return false
}

function onMapChanged(c, b, a) {
    em.setProperty("kill", "0");
    em.setProperty("level", "0");
    em.setProperty("clear", "0");
    em.setProperty("curMap", a);
    if (mapIds.indexOf(a) < 0) {
        on玩家退场(c, b, false);
        return
    }
}

function onPlayerDisconnected(b, a) {
    on玩家退场(b, a, false);
    return 0
}

function onMonsterDamaged(b, a, d, e, c) {}

function onTimeOut(a) {
    a.getPlayers().forEach(function (b) {
        on玩家退场(a, b, true)
    })
}

function onMonsterKilled(b, e, c) {
    var a = em.getNumberProperty("kill") + 1;
    em.setProperty("kill", a);
    var d = player.getAPI().addNumberForQuestInfo(100336, "energy", 5, 0, 101);
    if (d <= 100) {
        player.getAPI().cerniumLightningDefensePlayerEnergy(d)
    }
}

function onPartyDisbanded(a) {}

function onPlayerKilled(b, a) {}
var setupTask;

function randomNum(b, a) {
    switch (arguments.length) {
        case 1:
            return parseInt(Math.random() * b + 1, 10);
            break;
        case 2:
            return parseInt(Math.random() * (a - b + 1) + b, 10);
            break;
        default:
            return 0;
            break
    }
}

function initProp(a, b) {
    if (em.getProperty(a) == null) {
        em.setProperty(a, b)
    }
}

function initPropArray(a, d, c, e) {
    for (var b = c; b <= e; b++) {
        if (em.getProperty(a + "_" + b) == null) {
            em.setProperty(a + "_" + b, d)
        }
    }
}

function on玩家退场(c, b, a) {
    c.disposeIfPlayerBelow(a ? 999 : 0, 准备地图);
    em.getProperties().clear();
    em.setProperty("state", 0);
    em.setProperty("leader", "true");
    c.unregisterPlayer(b)
}

function onItemPickedUp(b, a, c) {};